/*
 * Course:    CS 590 Web Services
 * Semseter:  Spring 2009
 * Professor: Sedlemeyer
 * Project:   CHEAT (Code Help Educational Assignment Tool)
 * Due Date:  May 1, 2009
 * Team:      Sarcasm
 *            (Baker, Jason; Mitchell, Robin; Shie, Keith)
 */

package cheat.entities;

import cheat.entities.keys.AssignmentCustomPropertyPK;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * Holds the custom property metadata associated with the assignment.
 *
 * @author Keith Shie
 */
@Entity
@Table(name = "asgn_cust_prop")
@IdClass(AssignmentCustomPropertyPK.class)
@NamedQueries({@NamedQuery(name = "AssignmentCustomProperty.findAll",
              query = "SELECT a FROM AssignmentCustomProperty a"),
        @NamedQuery(name = "AssignmentCustomProperty.findByUuid", query =
        "SELECT a FROM AssignmentCustomProperty a WHERE a.uuid = :uuid"),
        @NamedQuery(name = "AssignmentCustomProperty.findByPropName", query =
        "SELECT a FROM AssignmentCustomProperty a WHERE a.name = :propName"),
        @NamedQuery(name = "AssignmentCustomProperty.findByPropValue", query =
        "SELECT a FROM AssignmentCustomProperty a WHERE a.propValue = :propValue")})
public class AssignmentCustomProperty implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @Basic(optional = false)
  @Column(name = "uuid", nullable = false)
  private int uuid;
  @Id
  @Basic(optional = false)
  @Column(name = "prop_name", nullable = false, length = 20)
  private String name;
  @Column(name = "prop_value", length = 50)
  private String propValue;
  @JoinColumns({@JoinColumn(name = "uuid", referencedColumnName = "uuid", nullable = false, insertable = false, updatable =
          false)})
  @ManyToOne(optional = false)
  private AssignmentProperty assignmentProperty;

  public AssignmentCustomProperty() {
  }

  public AssignmentCustomProperty(int uuid, String propName) {
    this.uuid = uuid;
    this.name = propName;
  }

  public AssignmentCustomProperty(int uuid, String name, String value) {
    this( uuid, name);
    this.propValue = value;
  }

  public String getName() {
    return name;
  }

  public void setName(String name) {
    this.name = name;
  }

  public int getUuid() {
    return uuid;
  }

  public void setUuid(int uuid) {
    this.uuid = uuid;
  }

  public String getPropValue() {
    return propValue;
  }

  public void setPropValue(String propValue) {
    this.propValue = propValue;
  }

  public AssignmentProperty getAssignmentProperty() {
    return assignmentProperty;
  }

  public void setAssignmentProperty(AssignmentProperty assignmentProperty) {
    this.assignmentProperty = assignmentProperty;
  }

  @Override
  public int hashCode() {
    int hash = 0;
    hash += (int) uuid;
    hash += (name != null ? name.hashCode() : 0);
    return hash;
  }

  @Override
  public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof AssignmentCustomProperty)) {
      return false;
    }
    AssignmentCustomProperty other = (AssignmentCustomProperty) object;
    if (this.uuid != other.uuid) {
      return false;
    }
    if ((this.name == null && other.name != null) || (this.name != null && !this.name.equals(other.name))) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "cheat.entities.AssignmentCustomProperty[uuid=" + uuid + ", name=" + name + "]";
  }

}
